#ifndef ANIMATIONS_H
#define ANIMATIONS_H

#include <stdint.h>
#include <string.h>

#define NUMBER_OF_LEDS	64
#define NUMBER_OF_LEDS_IDX (NUMBER_OF_LEDS-1)

typedef int8_t (*ANIMATION)( void );

typedef struct
{
	uint8_t		active;
	uint8_t		loop;
	uint8_t		currentFrame;
	uint16_t	ticksForCurrentFrame;
	uint8_t		nextFrameReady;
	uint8_t		currentAnimationIndex;
	ANIMATION	currentAnimation;
} animationState;

animationState animation;

extern uint8_t *buf[];
extern uint8_t frameBufferIdx;

#define FRAME() (buf[frameBufferIdx])
#define BUFFER() (buf[frameBufferIdx^1])
#define SWAP_BUFFER_INDEX() (frameBufferIdx^=1)

#define FILL_BUFFER( buf, val ) (memset( buf, val, 8))
#define CLEAR_BUFFER( buf ) ( FILL_BUFFER( buf, 0 ) )
#define CLEAR_BACK_BUFFER() ( CLEAR_BUFFER( BUFFER() ) )
#define CLEAR_FRAME_BUFFER() ( CLEAR_BUFFER( FRAME() ) )
#define COPY_FRAME_TO_BUFFER() ( memcpy( BUFFER(), FRAME(), 8 ) )

void setAnimationFunction( ANIMATION animFunc, uint8_t resetFrame, uint8_t activateAnimation, uint8_t loopAnimation );
void animationTick( void );
void animationBufferSwap( void );

//types of animation functions
int8_t anim_batteryLevel( void );
int8_t anim_movingDot( void );
int8_t anim_fillDot( void );
int8_t anim_spiral( void );
int8_t anim_showFont( void );
int8_t anim_scrollText( void );
int8_t anim_scrollText2( void );
int8_t anim_ski( void );
int8_t anim_linerun( void );
int8_t anim_blinkrect( void );
int8_t anim_blinkrect2( void );
int8_t anim_playpong( void );

extern ANIMATION animationList[];

#endif
